﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text.RegularExpressions;
using System.Security.Policy;
using System.Xml.Linq;
using StackExchange.Redis;

namespace CashFlow.ShopManage.Common
{
    public class RegExpTool
    {
        public static bool IsDate(string date)
        {
            string pattern = "(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|" +
            "((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|" +
            "((0[48]|[2468][048]|[3579][26])00))-02-29)$";
            Regex reg = new Regex(pattern);
            return reg.IsMatch(date);
        }

        public static bool IsPhone(string phone)
        {
            string pattern = "^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|166|198|199|(147))\\d{8}$";
            Regex reg = new Regex(pattern);
            return reg.IsMatch(phone);
        }

        public static bool IsName(string name)
        {
            string pattern = "[\\u4e00-\\u9fa5a-zA-Z0-9]{2,10}";
            Regex reg = new Regex(pattern);
            return reg.IsMatch(name);
        }

        public static bool IsInvitationCode(string code)
        {
            string pattern = "[A-Z]{6}";
            Regex reg = new Regex(pattern);
            return reg.IsMatch(code);
        }

        public static bool IsUserName(string username)
        {
            string pattern = "[a-zA-Z0-9]{5,20}";
            Regex reg = new Regex(pattern);
            return reg.IsMatch(username);
        }

        public static bool IsPassword(string pwd)
        {
            string pattern = "[a-zA-Z0-9]{6,20}";
            Regex reg = new Regex(pattern);
            return reg.IsMatch(pwd);
        }

        public static bool IsVerifyCode(string code)
        {
            string pattern = "[a-zA-Z0-9]{4}";
            Regex reg = new Regex(pattern);
            return reg.IsMatch(code);
        }

        public static bool IsOrderNo(string orderNo)
        {
            string pattern = "E[0-9]{19}";
            Regex reg = new Regex(pattern);
            return reg.IsMatch(orderNo);
        }
    }
}